<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Sausage</title>
<script type="text/javascript" src="./jquery.js"></script>
<script type="text/javascript" src="./display.js"></script>
</head>
<body>
	<h1>Find your Sausage!</h1>
	<div class="searchSection">
		<input type="text" id="query"
			onkeydown="if (event.keyCode == 13) document.getElementById('send').click()">
		<button id="send" onclick="javascript:sendRequest();">search</button>
	</div>
	<div class="moveSection">
	<h2>상세 검색 하기</h2>
		<div class="detailSearchMoveSection">
			<ul>
				<!-- <li><a href="companySearch.jsp"><button class="detailSearch">업체 기준 검색</button></a></li>
				<li><a href="provinceSearch.jsp"><button class="detailSearch">지역 기준 검색</button></a></li> -->
				<li><a href="categorySearch.jsp?c=company"><button class="detailSearch">업체 기준 검색</button></a></li>
				<li><a href="categorySearch.jsp?c=province"><button class="detailSearch">지역 기준 검색</button></a></li>
				<li><a href="categorySearch.jsp?c=item"><button class="detailSearch">품목 기준 검색</button></a></li>
			</ul>
		</div>
		<div class="companySearch">
		<h3>업체별 품목 전체 보기</h3>
			<ul>
				<li><button onclick="location.href='companyRetrieve.jsp?company=coupang';" >쿠팡</button></li>
				<li><button onclick="location.href='companyRetrieve.jsp?company=ticketmonster';">티켓몬스터</button>
				<li><button onclick="location.href='companyRetrieve.jsp?company=wemakeprice';">위메프</button></li>
			</ul>
		</div>
	</div>
	<div class="resultSection" id="result"></div>
</body>
<script type="text/javascript">

	function sendRequest() {
		/* var xmlhttp = new XMLHttpRequest();

		// code for IE7+, Firefox, Chrome, Opera, Safari
		if (window.XMLHttpRequest) {
			xmlhttp = new XMLHttpRequest();
		} else // code for IE6, IE5
		{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}

		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				$("#result").innerHTML = xmlhttp.responseXML;
			} else {
				$("#result").innerHTML = "No Result";
			}
		}
		var url = "rest/search/standard?q=" + $("#query").val();
		alert(url);
		xmlhttp.open("GET", url, true);
		xmlhttp.send();  */
		
		var url = "rest/search/standard?q=" + $("#query").val();
		$.get(url, function(data) {
			
			if(data == null) console.log("null");
			else
			{
				if(data.product.length > 1)
				{
					for(var i = 0; i < data.product.length; ++i)
					{
						var result = data.product[i];
						
						display(result);
					}
				}else
				{
					display(data.product);
				}
			}
			}, "json");
	}
	
	//$("button.companySearch").click(function (){ location.href="companyRetrieve.jsp?" + ; });
	//$("button.detailSearch").click(function() { console.log("click"); location.href = "companySearch.html"; });
	//$(".detailSearch").click(function() { console.log("click"); location.href = "companySearch.html"; });
	
</script>
</html>

